﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Last_Knights.Event;

namespace The_Last_Knights
{
    public class EventEntityDictionary
    {
        static Dictionary<string, List<EventEntity>> _dictionary = new Dictionary<string, List<EventEntity>>();

        public static bool Add(string key, EventEntity value)
        {
            if (!_dictionary.ContainsKey(key))
                _dictionary.Add(key, null);            
            List<EventEntity> eventEntities = _dictionary[key];
            if (eventEntities == null)
                eventEntities = new List<EventEntity>();
            else
            {
                if (eventEntities.Contains(value))
                    return false;                            
            }
            eventEntities.Add(value);
            return true;            
        }

        public static bool Remove(string key, EventEntity value)
        {
            if (_dictionary.ContainsKey(key))
            {
                List<EventEntity> eventEntities = _dictionary[key];
                if (eventEntities == null)
                    eventEntities = new List<EventEntity>();
                eventEntities.Remove(value);                
                return true;
            }
            return false;
        }

        public static bool IsContainKey(string key)
        {
            if (_dictionary.ContainsKey(key))
                return true;
            return false;
        }

        public static bool IsContainValue(string key, EventEntity value)
        {
            if (_dictionary.ContainsKey(key))
            {
                List<EventEntity> eventEntities = _dictionary[key];
                if (eventEntities == null)
                    eventEntities = new List<EventEntity>();
                return eventEntities.Contains(value);
            }                
            return false;
        }

        public static void Add(Dictionary<string, List<EventEntity>> value)
        {
            foreach (var o in value)
            {
                foreach (var eventEntity in o.Value)
                {
                    Add(o.Key, eventEntity);    
                }                
            }
        }

        public static void Remove(Dictionary<string, List<EventEntity>> value)
        {
            foreach (var o in value)
            {
                foreach (var eventEntity in o.Value)
                {
                    Remove(o.Key, eventEntity);                    
                }
            }
        }

        public static object GetValue(string key)
        {
            if (_dictionary.ContainsKey(key))
                return _dictionary[key];
            return null;
        }
    }
}
